package com.zhenmyan.secdeal.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * description:
 *
 * @author 颜真明
 * @date 2023/5/15  10:25
 */
@Configuration
public class RabbitMQHeadersConfig {

    private static final String HEADERS_QUEUE_1 = "headers_queue_1";

    private static final String HEADERS_QUEUE_2 = "headers_queue_2";

    private static final String HEADERS_EXCHANGE = "headers_exchange";

    @Bean
    public Queue headersQueue1() {
        return new Queue(HEADERS_QUEUE_1);
    }

    @Bean
    public Queue headersQueue2() {
        return new Queue(HEADERS_QUEUE_2);
    }

    @Bean
    public HeadersExchange headersExchange() {
        return new HeadersExchange(HEADERS_EXCHANGE);
    }

    /**
     * 满足map中的一个条件即可
     *
     * @return
     */
    @Bean
    public Binding headersBinding1() {
        Map<String, Object> map = new HashMap<>();
        map.put("color", "red");
        map.put("speed","fast");
        return BindingBuilder.bind(headersQueue1()).to(headersExchange()).whereAny(map).match();
    }

    /**
     * 需要满足map中的所有条件
     *
     * @return
     */
    @Bean
    public Binding headersBinding2() {
        Map<String, Object> map = new HashMap<>();
        map.put("color", "red");
        map.put("speed","low");
        return BindingBuilder.bind(headersQueue2()).to(headersExchange()).whereAll(map).match();
    }
}